package com.zmn.uac.client;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.uac.UacException;
import com.zmn.uuc.common.constant.DubboConsts;
import com.zmn.uuc.common.dio.user.UserRegisterByMobileNoCaptchaDIO;
import com.zmn.uuc.common.dio.user.UserRegisterByThirdAccountDIO;
import com.zmn.uuc.dubbo.interfaces.user.UserRegisterRemoteService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * @title: 个人用户注册Dubbo接口
 * @author:Rananquan
 * @Date:2022/6/9 16:36
 */
@Slf4j
@Component
public class UserRegisterClient {

    @DubboReference(version = DubboConsts.INTERFACE_VERSION, check = false)
    UserRegisterRemoteService userRegisterRemoteService;

    /**
     * 个人用户手机号不带验证码注册
     * @param dio
     * @return userId
     */
    public Long registerByMobileNoCaptcha(UserRegisterByMobileNoCaptchaDIO dio){
        log.info("个人用户手机号不带验证码注册入参：[{}]",dio);
        ResponseDTO<Long> userRegisterResponse = userRegisterRemoteService.registerByMobileNoCaptcha(dio);
        if(!userRegisterResponse.isSuccess()){
            log.error("个人用户手机号不带验证码注册请求失败，失败原因：{}",userRegisterResponse.getMessage());
            throw new UacException(userRegisterResponse.getMessage());
        }

        Long userId = userRegisterResponse.getData();
        log.info("个人用户手机号不带验证码注册返回response：{}",userId);

        return userId;
    }


    /**
     * 个人用户通过三方账户注册
     * @param dio
     * @return userId
     */
    public Long registerByThirdAccount(UserRegisterByThirdAccountDIO dio){
        log.info("个人用户通过三方账户注册入参：[{}]",dio);
        ResponseDTO<Long> userRegisterResponse = userRegisterRemoteService.registerByThirdAccount(dio);
        if(!userRegisterResponse.isSuccess()){
            log.error("个人用户通过三方账户注册请求失败，失败原因：{}",userRegisterResponse.getMessage());
            throw new UacException(userRegisterResponse.getMessage());
        }

        Long userId = userRegisterResponse.getData();
        log.info("个人用户通过三方账户注册返回response：{}",userId);

        return userId;
    }
}
